package MDVRPTW;

import java.util.LinkedList;

public class Solution {

	//优化目标个数
	public static final int NUMOBJECTS=4;
	//保存优化目标评价结果数组
	//private double[] objs;
	//实际使用的车辆数
	private int totalCars;
	//实际总路径长度
	private double totalDistance;
	//违背时间窗约束的总惩罚
	private double totalVoilation;
	//各车辆间服务时间方差
	private double timeVariance;
	//车辆路径集合
	LinkedList<Car> cars = new LinkedList<Car>();
	//记录各车场使用情况
	private int[] deportCount;
	//Pareto解集中支配该解的数量
	private int numControl;
	
	public Solution(){}
	//声明一个初始化方法，用于solution的深克隆
	public Solution(Solution s) {
		//this.objs=s.objs.clone();
		this.totalCars=s.totalCars;
		this.totalVoilation=s.totalVoilation;
		this.totalDistance=s.totalDistance;
		this.deportCount=s.deportCount.clone();
		this.numControl=s.numControl;
		this.timeVariance=s.timeVariance;
		LinkedList<Car> newS=new LinkedList<Car>();
		for (Car car : s.getCars()) {
			Car newCar=new Car(car);
			this.cars.add(newCar);
		}
	}
	
	public int getTotalCars() {
		return totalCars;
	}
	public void setTotalCars(int totalCars) {
		this.totalCars = totalCars;
	}
	public void setTotalCars() {
		this.totalCars = cars.size();
	}
	public double getTotalDistance() {
		return totalDistance;
	}
	public void setTotalDistance(double totalDistance) {
		this.totalDistance = totalDistance;
	}
	public void setTotalDistance() {
		double tDistance=0;
		for (Car car : cars) {
			tDistance+=car.getDistance();
		}
		this.totalDistance = tDistance;
	}
	public double getTotalVoilation() {
		return totalVoilation;
	}
	public void setTotalVoilation(double totalVoilation) {
		this.totalVoilation = totalVoilation;
	}
	public void setTotalVoilation() {
		double tVoilation=0;
		for (Car car : cars) {
			tVoilation+=car.getVoilation();
		}
		this.totalVoilation = tVoilation;
	}
	public double getTimeVariance() {
		return timeVariance;
	}
	public void setTimeVariance(double timeVariance) {
		this.timeVariance = timeVariance;
	}
	public void setTimeVariance() {
		double tVariance=0;
		double middle=0;
		for (Car car : cars) {
			middle+=car.getEndTime().getLast();
		}
		middle=middle/totalCars;
		for (Car car : cars) {
			tVariance+=(car.getDistance()-middle)*(car.getDistance()-middle);
		}
		this.timeVariance = tVariance/totalCars;
	}
	public LinkedList<Car> getCars() {
		return cars;
	}
	public void setCars(LinkedList<Car> cars) {
		this.cars = cars;
	}
//	public double[] getObjs() {
//		return objs;
//	}
//	public void setObjs(double[] objs) {
//		this.objs = objs;
//	}
	public int[] getDeportCount() {
		return deportCount;
	}
	public void setDeportCount(int[] deportCount) {
		this.deportCount = deportCount;
	}
	public int getNumControl() {
		return numControl;
	}
	public void setNumControl(int numControl) {
		this.numControl = numControl;
	}
	
	//输出当前方案的方法
	public void print(){
		int n=0;
		for (Car car : cars) {
			car.print();
			n+=car.getRoute().size()-2;
		}
		System.out.println("=================================================================================================");
		System.out.println("实际使用的车辆数:"+this.totalCars+"	共有顾客："+n+"个");
		System.out.println("实际总路径长度:"+this.totalDistance);
		System.out.println("违背时间窗约束的总惩罚:"+this.totalVoilation);
		System.out.println("各车辆间服务时间方差:"+this.timeVariance);
		System.out.println("=================================================================================================");
	}
}
